/*******************************************************************************
  
Replication file for: 

Gallego, Kurer and Schöll (2020):
"Neither Left-Behind nor Superstar: Ordinary Winners of Digitalization at the Ballot Box"



*******************************************************************************/

clear all
set more off, permanently
set scheme s1mono
capture set autotabgraphs on

// create folder for results
capture mkdir "results_paper"
capture mkdir "results_paper/temp"
capture mkdir "results_online_appendix"
capture mkdir "results_online_appendix/temp"

use "replication_data/dataset_final.dta", clear



********************************************************************************
****  Restrict sample          *************************************************
********************************************************************************

drop if age < 18 | age > 64 | age == . //focus on working age population
drop if year < 1997 // no ICT data 
drop if euklems_num == . // no ICT data
drop if edu == . // remove individuals where education level is missing
bysort indxind year: drop if _n > 1 //drop second observation if individual interviewed twice in same year (and same industry)


//gen duplicates dummy in terms of id year 
//(those need to be excluded when we use id-year FE)
bysort id year: gen duplicate_id_year = 1 if _n > 1


//set as panel (industry-spell fixed effects)
xtset indxind year


save "replication_data/dataset_restricted.dta", replace


********************************************************************************
*** FIGURE 1 : Digitalization: ICT capital stock per employee, by industry    **
********************************************************************************

// see R-script "4_online_appendix_figures.Rmd"
	
********************************************************************************
*** FIGURE 2 & 3: Effect of Digitalization on Economic and Political Outcomes **
********************************************************************************

xtset indxind year
capture graph drop *
foreach v in hourly_wage F_unemployed voted incumbent  cons labour {
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 
	
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe r
 	
	margins, dydx(ICT) at(edu=(0(1)5))
	marginsplot, plotopts(connect(none)) xline(0) horizontal ///
		title(`"`vtext'"') ytitle("") xtitle("Marginal effect of digitalization (ICT/worker)") 	///
		xscale(r(0  0.0001)) ///		
		name(`v') ///
		saving(results_paper/temp/`v', replace)
} 

*************************** COMBINE GRAPHS


*** FIGURE 2: Effect of ICT capital stock increases on labor market outcomes
graph combine ///
	"results_paper/temp/hourly_wage.gph" ///
	"results_paper/temp/F_unemployed.gph", /// 
	col(2) imargin(2 2 2 2) iscale(1) ysize(3) xsize(6) 
graph export "results_paper/fg2.eps", replace


*** FIGURE 3: Effect of digitalization on political outcomes, industry-spells fixed effect specification
graph combine ///
	"results_paper/temp/voted.gph" ///
	"results_paper/temp/cons.gph" ///
	"results_paper/temp/labour.gph" ///
	"results_paper/temp/incumbent.gph", /// 
	col(2) imargin(2 2 2 2) iscale(0.5) ysize(6) xsize(6) 
graph export "results_paper/fg3.eps", replace
	
	
	
********************************************************************************
********* Table 1: Sub-period Analysis: Until May 2010 and after May 2010 ******
********************************************************************************
//compare pre and post 2010 results for Labour & Conservatives
label var ICT "ICT"
eststo clear
foreach v in labour cons {
	di "`v'"
	di "0: Pre 2010"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year if interview_date < mdy(5, 10, 2010), fe cluster(id)

	eststo `v'_pre 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "1: Post 2010"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year if interview_date >= mdy(5, 10, 2010), fe cluster(id)
	eststo `v'_post
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "2: Overall"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	eststo `v'_all
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
} 	


//add incumbent
foreach v in incumbent {
	di "`v' all"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	eststo `v'_all
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace

} 

*display
esttab, ///
	drop(_cons *.year *.region 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 /// 
	mgroups("Vote for Labour" "Vote for Conservatives" "Incumbent", pattern(1 0 0 1 0 0 1) ) ///
	mtitle("Pre May 2010" "Post May 2010" "Overall" "Pre May 2010" "Post May 2010" "Overall" "Overall") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE  edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations")) label nolegend postfoot("")
	
	

*save
label var ICT "ICT"
esttab using "results_paper/table_1.tex", replace ///
	drop(_cons *.year *.region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu) se ar2 /// 
	mgroups("Vote for Labour" "Vote for Conservatives" "Incumenbent", pattern(1 0 0 1 0 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) span ) ///
	mtitle("Pre May 2010" "Post May 2010" "Overall" "Pre May 2010" "Post May 2010" "Overall" "Overall") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE  edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations")) ///
	label nolegend postfoot("\hline \hline \\ \end{tabular}}")
	
	

********************************************************************************
*****    FIGURE 4: Effect of digitalization on UKIP support,			 ******* 
*****    industry-spells fixed effect specification  					 *******
********************************************************************************

quietly xtreg ukip c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe r
 	
margins, dydx(ICT) at(edu=(0(1)5))
marginsplot, plotopts(connect(none)) xline(0) horizontal ///
	title ("") ytitle("") xtitle("Marginal effect of digitalization (ICT/worker)") 	///
	xscale(r(0  0.0001))
graph export "results_paper/fg4.eps", replace


********************************************************************************
***** TABLE 2: Instrumental Variable Results:  Economic Outcomes         *******
********************************************************************************
*Now we can cluster on the individual level, before it did not work because of the margins command so we use robust

*** preparation IV using xtivreg2 which does not allow for factor variables
capture ssc install ranktest
capture ssc install ivreg2
capture ssc install xtivreg2

***FE & IV: Economics
eststo clear
foreach v in hourly_wage F_unemployed {
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 	

	di "FE"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	quietly eststo FE_`v'
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace

	
	di "IV"
	quietly xtivreg2 `v' (ICT__*  = ICT_USA__* )  age agesq ///
		year_*  edu_6 edu_5 edu_4 edu_3 edu_2 region_* , fe  cluster(id) first partial(year_* region_*)
	quietly eststo IV_`v'
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd scalar first_stage = e(rkf) //Kleibergen-Paap Wald rk F statistic [this is the F-stat if we cluster SE in in first stage]	
} 

*display
esttab, ///
	drop(_cons *year *region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu edu*) se ar2 ///
	mgroups("Hourly net wage" "Probability to become unemployed", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span ) ///
	mtitle("Main specification" "Instrumental variable""Main specification" "Instrumental variable" ) /// 
	rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
		   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", 4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT", ///
		   agesq "c.age#c.age") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N first_stage, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations" "First stage F-stat")) label nolegend postfoot("\hline \hline \\ \end{tabular}}")

*save 
esttab using "results_paper/table_2.tex", replace ///
	drop(_cons *year *region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu edu*) se ar2 ///
	mgroups("Hourly net wage" "Probability to become unemployed", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span ) ///
	mtitle("Main specification" "Instrumental variable""Main specification" "Instrumental variable" ) /// 
	rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
		   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", 4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT", ///
		   agesq "c.age#c.age") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N first_stage, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations" "First stage F-stat")) ///
	label nolegend postfoot("\hline \hline \\ \end{tabular}}")

	
********************************************************************************
***** TABLE 3: Instrumental Variable Results:  Political Outcomes        *******
********************************************************************************
eststo clear
foreach v in voted cons labour incumbent  {
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 	

	di "FE"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	quietly eststo FE_`v'
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "IV"
	quietly xtivreg2 `v' (ICT__*  = ICT_USA__* ) age agesq ///
		year_* edu_6 edu_5 edu_4 edu_3 edu_2 region_* , fe  cluster(id) first partial(year_* region_*)
	quietly eststo IV_`v'
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd scalar first_stage = e(rkf) //Kleibergen-Paap Wald rk F statistic [this is the F-stat if we cluster SE in in first stage]	
} 

*display
esttab, ///
	drop(_cons *year *region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu edu*)  se ar2 ///
	mgroups("Turnout" "Conservatives" "Labour" "Incumbent", pattern(1 0 1 0 1 0 1 0)) ///
	mtitle("Main" "IV" "Main" "IV" "Main" "IV" "Main" "IV") /// 
	rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
		   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", 4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT", ///
		   agesq "c.age#c.age") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N first_stage, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations" "First stage F-stat")) label

*save
esttab using "results_paper/table_3.tex", replace ///
	drop(_cons *year *region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu edu*)  se ar2 /// 
	mgroups("Turnout" "Conservatives" "Labour" "Incumbent", pattern(1 0 1 0 1 0 1 0) ///
	prefix(\multicolumn{@span}{c}{) suffix(}) span  erepeat(\cmidrule(lr){@span})) ///
	mtitle("Main" "IV" "Main" "IV" "Main" "IV" "Main" "IV") /// 
	rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
		   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", 4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT", ///
		   agesq "c.age#c.age") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N first_stage, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations" "First stage F-stat")) ///
	label  nolegend postfoot("\hline \hline \\ \end{tabular}}")


	
	
	
	
	
	
*------------------------------------------------------------------------------*	
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*---------------------      ONLINE APPENDIX        ----------------------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

	
********************************************************************************
**************  Summary Stats   *******************************
********************************************************************************
capture ssc install unique
unique id 
unique indxind 
//--> Number of unique values of id is  60029
//Number of unique values of indxind is  85479
//Number of records is  276855

est clear
estpost summarize year voted cons labour libdem ukip incumbent euklems_num ICT machinery nonICT ICT_USA imports ///
	region female immigrant age agesq edu incomem hourly_wage F_unemployed high_rti ///
	strong_gov_pca social_progressive_pca satlife_imp
	
esttab, cells( "count mean(fmt(%5.2f)) sd(fmt(%5.2f)) min(fmt(%5.2f)) max(fmt(%5.2f))") nonum nomtitle label ///
	addnotes(`"Note: ICT defined as "real fixed ICT capital stock (in 2010 GBP) normalized by hours worked"."')

esttab using "results_online_appendix/SI_summary_stats.tex", replace ///
	cells( "count mean(fmt(%5.2f)) sd(fmt(%5.2f)) min(fmt(%5.2f)) max(fmt(%5.2f))") nonum nomtitle label ///
	addnotes(`"Note: ICT defined as "real fixed ICT capital stock (in 2010 GBP) normalized by hours worked"."')
	

********************************************************************************
******** FIGURE SI1.6: Main outcomes split by high and low RTI  ****************
********************************************************************************
* Compare effects for occupations above and below the median level of routine task intensity 
capture graph drop *
foreach v in  hourly_wage F_unemployed voted incumbent  cons labour { //
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 
	
	quietly xtreg `v' c.ICT##i.edu##high_rti i.edu c.age##c.age i.year, fe r
 	
	margins, dydx(ICT) at(edu=(0(1)5)) over(high_rti)
	marginsplot, plotopts(connect(none)) xline(0) horizontal ///
		title(`"`vtext'"') ytitle("") xtitle("Marginal effect of digitalization (ICT/worker)") 	///
		xscale(r(0  0.0001)) ///		
		name(`v'_FE) legend(off) ///
		saving(results_online_appendix/temp/`v'_rti, replace)
}




*************************** COMBINE GRAPHS
* Economic and political outcomes combined
graph combine ///
	"results_online_appendix/temp/hourly_wage_rti.gph" ///
	"results_online_appendix/temp/F_unemployed_rti.gph" /// 
	"results_online_appendix/temp/voted_rti.gph" ///
	"results_online_appendix/temp/cons_rti.gph" ///
	"results_online_appendix/temp/labour_rti.gph" ///
	"results_online_appendix/temp/incumbent_rti.gph", /// 
	col(2) imargin(2 2 2 2) iscale(0.5) ysize(6) xsize(6) 
graph export "results_online_appendix/SI_Combined_rti.eps", replace


********************************************************************************
**** TABLE SI1.1 Economic Effects Before and After the 2010 Government Change  *
********************************************************************************	
	
//compare pre and post change of Government change from Brown to Cameron in May 2010
eststo clear
foreach v in hourly_wage F_unemployed{
	di "`v'"
	di "0: Pre 2010"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year if interview_date < mdy(5, 10, 2010), fe cluster(id)
	eststo `v'_pre 
	quietly estadd local year_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local indxind_FE "X" , replace
	
	di "1: Post 2010"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year if interview_date >= mdy(5, 10, 2010), fe cluster(id)
	eststo `v'_post
	quietly estadd local year_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local indxind_FE "X" , replace
} 
*display
esttab, ///
	drop(_cons *.year *.region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu) se ar2 ///
	mgroups("Hourly Wage" "Unemployment", pattern(1 0 1 0)) ///
	mtitle("Pre May 2010" "Post May 2010" "Pre May 2010" "Post May 2010") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region" "Observations")) ///
	label

*save
esttab using "results_online_appendix/SI_table_econ_pre_post.tex", replace ///
	drop(_cons *.year *.region 0.edu 1.edu 2.edu 3.edu 4.edu 5.edu) se ar2 ///
	mgroups("Hourly Wage" "Unemployment", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span  erepeat(\cmidrule(lr){@span}) ) ///
	mtitle("Pre May 2010" "Post May 2010" "Pre May 2010" "Post May 2010") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region" "Observations")) ///
	label nolegend postfoot("\hline \hline \\ \end{tabular}}")

	
********************************************************************************
**************  TABLES SI1.3 - SI1.8: Robustness Checks for Main Outcomes ******
********************************************************************************
label var imports "Imports"
label var female "Female"
foreach v in  hourly_wage F_unemployed voted cons labour incumbent libdem ukip {
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 	
	eststo clear
	
	di "1: indXind FE"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	eststo Main_`v', 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "2: IV"
	quietly xi: xtivreg `v' (ICT__*  = ICT_USA__* )  c.age##c.age ///
		i.year ib0.edu i.region , fe vce(cluster id)
	eststo IV_`v'
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "3: Non-ICT capital stock"
	quietly xtreg `v' c.nonICT#i.edu i.edu c.age##c.age i.region i.year_region, fe cluster(id)
	eststo Placebo_`v'	
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "4: Year*Region FE"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year_region, fe cluster(id)
	eststo Region_`v'	
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_region_FE "X" , replace
	
	di "5: Exclude outliers"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year if !inlist(euklems_num, 2, 7, 27), fe cluster(id)		
	eststo Exclude_`v'	
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "6: indXind FE lead"
	quietly xtreg F_`v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	eststo indxind_F_`v', 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "7: ID FE"
	preserve 
	drop if duplicate_id_year == 1
	quietly xtset id year
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year i.euklems_num, fe cluster(id)
	eststo id_`v', 
	quietly estadd local year_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local id_FE "X" , replace
	quietly estadd local industry_FE "X", replace
	quietly xtset indxind year
	restore
	quietly xtset indxind year
	
	di "8: Trade"
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year imports, fe cluster(id)
	eststo Trade_`v', 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	
	di "9: OLS"
	quietly reg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year i.euklems_num female, r
	eststo OLS_`v', 
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local industry_FE "X", replace

	*display
	esttab, ///
		drop(_cons *year *region *euklems_num _Iyear_* _Iregion* 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 ///
		mtitle("Main" "IV" "Placebo" "Region*Year FE" "Excl. outliers" "Lead" "ID FE" "Trade" "Cross Sect") /// 
		rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
			   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", ///
			   4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT") ///
		order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
		s(indxind_FE edu_FE year_FE region_FE year_region_FE id_FE industry_FE  N, ///
		label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Year*Region FE" "Individual FE" "Industry FE" "Observations")) label
	
	*save table
	esttab using "results_online_appendix/SI_table_`v'.tex", replace ///
		drop(_cons *year *region *euklems_num _Iyear_* _Iregion* 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 ///
		mtitle("Main" "IV" "Placebo" "Region*Year FE" "Excl. outliers" "Lead" "ID FE" "Trade" "Cross Sect") /// 
		rename(ICT__6 "5.edu#c.ICT", ICT__5 "4.edu#c.ICT", ICT__4 "3.edu#c.ICT", ICT__3 "2.edu#c.ICT", ICT__2 "1.edu#c.ICT", ICT__1 "0.edu#c.ICT", ///
			   0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", ///
			   4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT") ///
		order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
		s(indxind_FE edu_FE year_FE region_FE year_region_FE id_FE industry_FE  N, ///
		label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Year*Region FE" "Individual FE" "Industry FE" "Observations")) ///
		label  nolegend postfoot("\hline \hline \\ \end{tabular}}")
} 


	

********************************************************************************
*********** Table SI1.9: Predictors of attrition  ******************************
********************************************************************************	
eststo clear
foreach attr_var in attr_sample attr_industry {
	quietly reg `attr_var' ICT i.year i.region, cluster(id)
	quietly eststo
	quietly estadd local year_FE "X", replace
	quietly estadd local region_FE "X" , replace
	quietly estadd local indxind_FE "X" , replace
	
	quietly xtreg `attr_var' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe cluster(id)
	quietly eststo
	quietly estadd local year_FE "X" , replace
	quietly estadd local edu_FE "X"
	quietly estadd local region_FE "X" , replace
	quietly estadd local indxind_FE "X" , replace
}

esttab, ///
	drop(_cons *year *region 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se  label ///
	mgroups("Leave sample" "Change industry", pattern(1 0 1 0)) ///
	mtitle("" "" "" "") ///
		order(ICT 5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region" "Observations")) nolegend postfoot("")

esttab using "results_online_appendix/SI_table_attrition.tex", replace ///
	drop(_cons *year *region  5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se  label ///
	mgroups("Leave sample" "Change industry", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span  erepeat(\cmidrule(lr){@span}) ) ///
	mtitle("" "" "" "") ///
		order(ICT 5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region" "Observations")) nolegend postfoot("\hline \hline \\ \end{tabular}}")

	
	
*******************************************************************************************
* Table SI1.10: All Outcomes with Standard Errors Clustered at the Industry-Year Level  ***
*******************************************************************************************
eststo clear
foreach v in hourly_wage F_unemployed voted cons labour incumbent {	
	di "`v'"
	quietly: xtreg `v'  c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe vce(cluster industry_year) nonest dfadj
	eststo `v' 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	}
	
esttab, ///
	drop(_cons *.year *.region 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 ///
	mtitle("Hourly wage" "Unemployed" "Turnout" "Conservative" "Labour" "Incumbent") ///
	rename(0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", ///
		   4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE"  "Year FE" "Region FE" "Observations")) label nolegend postfoot("")
		
*save
esttab using "results_online_appendix/SI_table_alternative_clustering.tex", replace ///
	drop(_cons *.year *.region  5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 ///
	mtitle("Hourly wage" "Unemployed" "Turnout" "Conservative" "Labour" "Incumbent") ///
	rename(_Iedu_1 1.edu, _Iedu_2 2.edu _Iedu_3 3.edu _Iedu_4 4.edu _Iedu_5 5.edu) ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE"  "Year FE" "Region FE" "Observations")) label nolegend postfoot("\hline \hline \\ \end{tabular}}")
	
	
	
********************************************************************************
*******    Table SI1.11: All Outcomes Excluding Foreign-Born Workers ***********
********************************************************************************
eststo clear
foreach v in hourly_wage F_unemployed voted cons labour incumbent  ukip {	
	di "`v'"
	quietly: xtreg `v'  c.ICT#i.edu i.edu c.age##c.age i.region i.year if immigrant == 0, fe cluster(id)
	eststo `v' 
	quietly estadd local indxind_FE "X" , replace
	quietly estadd local edu_FE "X" , replace
	quietly estadd local year_FE "X" , replace
	quietly estadd local region_FE "X" , replace
	}
	
esttab, ///
	drop(_cons *.year *.region 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 ///
	mtitle("Hourly wage" "Unemployed" "Turnout" "Conservative" "Labour" "Incumbent" "UKIP") ///
	rename(0.edu#c.nonICT "0.edu#c.ICT", 1.edu#c.nonICT "1.edu#c.ICT", 2.edu#c.nonICT "2.edu#c.ICT", 3.edu#c.nonICT  "3.edu#c.ICT", ///
		   4.edu#c.nonICT "4.edu#c.ICT", 5.edu#c.nonICT "5.edu#c.ICT") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT 0.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE"  "Year FE" "Region FE" "Observations")) label nolegend postfoot("")
		
*save
esttab using "results_online_appendix/SI_table_exclude_migrants.tex", replace ///
	drop(_cons *.year *.region 5.edu 4.edu 3.edu 2.edu 1.edu 0.edu) se ar2 /// 
	mtitle("Hourly wage" "Unemployed" "Turnout" "Conservative" "Labour" "Incumbent" "UKIP") ///
	order(5.edu#c.ICT 4.edu#c.ICT 3.edu#c.ICT 2.edu#c.ICT 1.edu#c.ICT) ///
	s(indxind_FE edu_FE year_FE region_FE N, label("Individual*Industry FE" "Education Level FE" "Year FE" "Region FE" "Observations")) label nolegend postfoot("\hline \hline \\ \end{tabular}}")

	
********************************************************************************
**************  TABLES SI1.12 - SI1.13: Other political outcomes         *******
********************************************************************************

// see TABLES SI1.3 - SI1.8: Robustness Checks for Main Outcomes


********************************************************************************
*** Figure SI1.7: Effect of digitalization on satisfaction and attitudes   *****
********************************************************************************

graph drop *
foreach v in strong_gov_pca social_progressive_pca   satlife_imp { 
	di "Now processing: `v'"
	local vtext : variable label `v' 
	if `"`vtext'"' == "" local vtext "`v'" 
	
	quietly xtreg `v' c.ICT#i.edu i.edu c.age##c.age i.region i.year, fe r
 	
	margins, dydx(ICT) at(edu=(0(1)5))
	marginsplot, plotopts(connect(none)) xline(0) horizontal ///
		title(`"`vtext'"') ytitle("") xtitle("Marginal effect of digitalization") 	///
		xscale(r(0  0.0001)) ///		
		name(`v') ///
		saving(results_online_appendix/temp/`v', replace)
} 

graph combine ///
	"results_online_appendix/temp/satlife_imp.gph" ///
	"results_online_appendix/temp/strong_gov_pca.gph" ///
	"results_online_appendix/temp/social_progressive_pca.gph", /// 
	col(2) imargin(2 2 2 2) iscale(.5) ysize(6) xsize(6) 
	
graph export "results_online_appendix/SI_figure_mechanism.eps", replace

*** TEST: Is there a significant difference between degree and no-quali group for life satistaction?
// YES. No quali group significantly less satisfied than GCSE - degree group. 
xtreg satlife_imp c.ICT##i.edu i.edu c.age##c.age i.region i.year, fe r
		


	

********************************************************************************
**************                  END                     ************************
********************************************************************************




